#include <stdio.h>
#include <math.h>
#include <conio.h>
#include "FGES.h"

void exit(void){
     system(pulisci);
     printf("Name: FGES First Grade Equation Solver\n");
     printf("Version: 0.1 \n");
     printf("Author: Damiano Andreghetti\n");
     printf("Official site: www.ilblogdidami.blogspot.com\n\n");
     printf("Press anykey to continue...");
     getch();
}
void FGES(){
    int scelta;
    float a,b,c,x;
    system(pulisci);
    printf("Welcome in First Grade Equation Solver (FGES). We are not sure the results will be correct but probably they will.\n\n");
    printf("Type of equation ax+b=c\n\n");
    printf("Please enter a,b,c separated by commas\n");
    scanf("%f,%f,%f",&a,&b,&c);
    printf("\n%fx=%f-%f",a,c,b);
    printf("\n%fx=%f",a,c-b);
    x = (c-b)/a;
    printf("\n=>x = %f\n",x);
    printf("Select one of the following options:\n\n ");
    printf("1)Return to the main menu\n\n ");
    printf("0)Exit\n\n ");
    printf("Your choice >> ");
    scanf("%i",&scelta);
    scelta=(int)scelta;
    if (scelta==1)
    {
    main();
    }
    else if (scelta==0)
    {
    exit();
    }
    else 
    {
    error_1();
    }   
}
void error_1(){
    int scelta;
    system(pulisci);
    printf("Your chice is not valid. Please choose one of the following options and press Enter:\n\n");
    printf("1)Return to the main menu\n\n");
    printf("0)Exit\n\n");
    printf("Your choice >> ");
    scanf("%i",&scelta);
    scelta=(int)scelta;
    for(;;){
    if (scelta==1)
    {
    main();
    }
    else if (scelta==0)
    {
    getch();
    }
    else
    {
    error_1();
    }
}
}  
int main(){
    int scelta;
    system(pulisci);
    printf("This is a C program to solve first grade equations. Please choose one of the following option and press Enter:\n\n");
    printf("1)Go to First Grade Equation Solver\n\n");
    printf("0)Exit\n\n");
    printf("Your choice >> ");
    scanf("%i",&scelta);
    scelta=(int)scelta;
    if (scelta==1)
    {
    FGES();
    }
    else if (scelta==0)
    {
    exit();
    }
    else 
    {
    error_1();
    }
}
